package com.lq.learningTest.duoxiancheng;

public class yeild {
    public static int count = 0;
    public static int count1 = 0;

    public static void addCount1() {
        System.out.println(Thread.currentThread().getName()+":"+count ++);
    }

    public static void addCount2() {
        System.out.println(Thread.currentThread().getName()+":"+count1 ++);
    }
    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 1000; i++) {
                    Thread.yield();
                    addCount1();
                }
            }
        },"t1").start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 1000; i++) {
                    addCount2();
                }
            }
        },"t2").start();
    }
}
